C++ Recipes: A Problem-Solution Approach by Sutherland Bruce

C++ Recipes: A Problem-Solution Approach by Sutherland Bruce

Author:Sutherland, Bruce [Sutherland, Bruce]
Language: eng
Format: azw3
ISBN: 9781484201589
Publisher: Apress
Published: 2015-05-14T16:00:00+00:00


int GetNumber() const

{

return m_Number;

}

};

using UniqueMyClass = unique_ptr< MyClass >;

void CreateUniqueObject()

{

UniqueMyClass uniqueMyClass{ make_unique<MyClass>(10) };

}

int main(int argc, char* argv[])

{

cout << "Begin Main!" << endl;

CreateUniqueObject();

cout << "Back in Main!" << endl;

return 0;

}

The unique_ptr in Listing 10-10 is created inside a function to demonstrate that the instance of the dynamically created object is destroyed when the unique_ptr goes out of scope. You can see this reflected in the output in Figure 10-9.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.